#-*-Makefile-*- vim:syntax=make
#
# Copyright (c) 2008-2012 the MansOS team. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#  * Redistributions of source code must retain the above copyright notice,
#    this list of  conditions and the following disclaimer.
#  * Redistributions in binary form must reproduce the above copyright
#   notice, this list of conditions and the following disclaimer in the
#   documentation and/or other materials provided with the distribution.
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#============================================================================
#	Platform-independent Hardware Interface Layer - HIL
#============================================================================

#===== Component locations =====
PDFS      = $(MOS)/fs
PDFATFS   = $(MOS)/fatfs
NET       = $(MOS)/net
PROTOTHR  = $(MOS)/kernel/protothreads

#===== Sources =====

PSOURCES += $(MOS)/hil/errors.c
PSOURCES-$(USE_SPI) += $(MOS)/hil/spi.c
PSOURCES-$(USE_SERIAL) += $(MOS)/hil/serial.c
PSOURCES-$(USE_ADC) += $(MOS)/hil/adc.c
PSOURCES-$(USE_LEDS) += $(MOS)/hil/leds.c
PSOURCES-$(USE_SOFT_I2C) += $(MOS)/hil/i2c_soft.c
PSOURCES-$(USE_SOFT_SPI) += $(MOS)/hil/spi_soft.c
PSOURCES-$(USE_DYNAMIC_MEMORY) += $(MOS)/hil/mem.c

PSOURCES += $(MOS)/kernel/kernelmain.c
PSOURCES-$(USE_ALARMS) += $(MOS)/kernel/alarms.c

PSOURCES-$(USE_PRINT) += $(MOS)/lib/dprint.c
PSOURCES-$(USE_SERIAL) += $(MOS)/lib/dprint-serial.c
PSOURCES-$(USE_RADIO) += $(MOS)/lib/dprint-radio.c
PSOURCES-$(USE_ASSERT) += $(MOS)/lib/assert.c
PSOURCES-$(USE_RANDOM) += $(MOS)/hil/random.c
PSOURCES-$(USE_PRINT) += $(MOS)/lib/usart_packet.c
PSOURCES-$(USE_GPS) += $(MOS)/lib/nmea/nmea.c
PSOURCES-$(USE_GPS) += $(MOS)/lib/nmea/nmea_stream.c
PSOURCES-$(USE_HASH) += $(MOS)/lib/hash.c
PSOURCES-$(USE_ACTIVE_MSG_SERIAL) += $(MOS)/lib/tosmsg.c
PSOURCES-$(USE_ACTIVE_MSG_RADIO) += $(MOS)/lib/activemsg.c
PSOURCES-$(USE_CRC) += $(MOS)/lib/codec/crc.c
# Data processing
PSOURCES-$(USE_ALGO) += $(MOS)/lib/algo.c
PSOURCES-$(USE_AVERAGE) += $(MOS)/lib/processing/average.c
PSOURCES-$(USE_STDEV) += $(MOS)/lib/processing/stdev.c
PSOURCES-$(USE_FILTER) += $(MOS)/lib/processing/filter.c
PSOURCES-$(USE_CACHE) += $(MOS)/lib/processing/cache.c

PSOURCES-$(USE_NET) += $(NET)/socket.c
PSOURCES-$(USE_NET) += $(NET)/networking.c
PSOURCES-$(USE_NET) += $(NET)/mac.c

PSOURCES-$(USE_THREADS) += $(MOS)/kernel/threads/main.c
PSOURCES-$(USE_THREADS) += $(MOS)/kernel/threads/mutex.c
PSOURCES-$(USE_THREADS) += $(MOS)/kernel/threads/threads.c
PSOURCES-$(USE_THREADS) += $(MOS)/kernel/threads/timing.c

ifeq ($(USE_THREADS),y)

PSOURCES += $(MOS)/kernel/sleep.c
PSOURCES-$(USE_RADIO) += $(MOS)/kernel/threads/radio.c
PSOURCES-$(USE_NET_STATS) += $(NET)/net_stats.c

ifeq ($(CONST_MAC_PROTOCOL),MAC_PROTOCOL_NULL)
PSOURCES-$(USE_NET) += $(NET)/mac/null.c
else
ifeq ($(CONST_MAC_PROTOCOL),MAC_PROTOCOL_CSMA)
PSOURCES-$(USE_NET) += $(NET)/mac/csma.c
PSOURCES-$(USE_NET) += $(NET)/queue.c
else
ifeq ($(CONST_MAC_PROTOCOL),MAC_PROTOCOL_CSMA_ACK)
PSOURCES-$(USE_NET) += $(NET)/mac/csma-ack.c
PSOURCES-$(USE_NET) += $(NET)/queue.c
else
ifeq ($(CONST_MAC_PROTOCOL),MAC_PROTOCOL_SAD)
PSOURCES-$(USE_NET) += $(NET)/mac/sad.c
else
#$(error "Error: no MAC protocol selected!")
endif
endif
endif
endif

ifeq ($(USE_ROLE_BASE_STATION),y)

ifeq ($(CONST_ROUTING_PROTOCOL),ROUTING_PROTOCOL_SAD)
ifeq ($(CONST_SINGLE_HOP),1)
PSOURCES-$(USE_NET) += $(NET)/routing/sad-bs-single.c
else
PSOURCES-$(USE_NET) += $(NET)/routing/sad-bs.c
endif
else
PSOURCES-$(USE_NET) += $(NET)/routing/dv-bs.c
endif

else # not base station

ifeq ($(CONST_ROUTING_PROTOCOL),ROUTING_PROTOCOL_SAD)

ifeq ($(USE_ROLE_FORWARDER),y)
PSOURCES-$(USE_NET) += $(NET)/routing/sad-fwd.c
else
ifeq ($(USE_ROLE_COLLECTOR),y)
PSOURCES-$(USE_NET) += $(NET)/routing/sad-coll.c
else
ifeq ($(CONST_SINGLE_HOP),1)
PSOURCES-$(USE_NET) += $(NET)/routing/sad-mote-single.c
else
PSOURCES-$(USE_NET) += $(NET)/routing/sad-mote.c
endif
endif
endif

else
PSOURCES-$(USE_NET) += $(NET)/routing/dv.c
endif

endif

else #! USE_THREADS

PSOURCES-$(USE_HARDWARE_TIMERS) += $(MOS)/kernel/sleep.c
PSOURCES-$(USE_HARDWARE_TIMERS) += $(MOS)/kernel/nothreads/timing.c
PSOURCES-$(USE_HARDWARE_TIMERS) += $(MOS)/kernel/nothreads/sleep.c


ifeq ($(USE_PROTOTHREADS),y)
INCLUDES += -I$(PROTOTHR)
PSOURCES += $(PROTOTHR)/process.c
PSOURCES += $(PROTOTHR)/protosched.c
PSOURCES += $(PROTOTHR)/autostart.c
PSOURCES += $(PROTOTHR)/etimer.c
PSOURCES += $(PROTOTHR)/timer.c
PSOURCES-$(USE_RADIO) += $(PROTOTHR)/radio.c
endif # PROTOTHREADS

endif # ifeq($(USE_THREADS),y)

PSOURCES-$(USE_NET) += $(MOS)/lib/buffer.c
PSOURCES-$(USE_HD4478_LCD) += $(MOS)/chips/hd4478/hd4478.c
PSOURCES-$(USE_MCP9804) += $(MOS)/chips/mcp9804/mcp9804.c
PSOURCES-$(USE_ADXL345) += $(MOS)/chips/adxl345/adxl345.c
PSOURCES-$(USE_TMP102) += $(MOS)/chips/tmp102/tmp102.c

PSOURCES-$(USE_REPROGRAMMING) += $(MOS)/kernel/boot.c
PSOURCES-$(USE_REPROGRAMMING) += $(MOS)/kernel/reprogramming.c

PSOURCES-$(USE_SMP) += $(MOS)/smp/smp.c
PSOURCES-$(USE_SMP) += $(MOS)/smp/proxy.c
PSOURCES-$(USE_SMP) += $(MOS)/smp/codec.c
PSOURCES-$(USE_SMP) += $(MOS)/smp/command.c

# Web management protocol
PSOURCES-$(USE_WMP) += $(MOS)/wmp/wmp.c

ifneq ($(USE_NET),y)
PSOURCES += $(MOS)/net/nonet.c
endif

PSOURCES-$(USE_FLASH_STREAM) += $(MOS)/hil/flash_stream.c
PSOURCES-$(USE_SDCARD_STREAM) += $(MOS)/hil/sdstream.c

PSOURCES-$(USE_FS) += \
	$(PDFS)/core.c        \
	$(PDFS)/prefix.c      \
	$(PDFS)/dev/dev.c     \
	$(PDFS)/dev/leds.c    \
	$(PDFS)/dev/null.c    \
	$(PDFS)/block/block.c \
	$(PDFS)/block/meta.c  \
	$(PDFS)/block/alloc.c

PSOURCES-$(USE_FATFS) += $(PDFATFS)/fatfs.c
PSOURCES += $(PDFATFS)/posix-stdio.c

PSOURCES-$(USE_SEAL_NET) += $(MOS)/net/seal_networking.c

PSOURCES-$(USE_TIMESYNC) += $(MOS)/net/timesync.c

PSOURCES-$(USE_ENERGY_STATS) += $(MOS)/lib/energy.c

PSOURCES-$(USE_DCO_RECALIBRATION) += $(MOS)/hil/dco.c
